import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';
import { ResponseInterceptor } from './common/interceptors/response';
import { AllExceptionsFilter } from './common/interceptors/exception';
import { NestExpressApplication } from '@nestjs/platform-express/interfaces';
import path from 'path'
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 配置 Swagger
  const options = new DocumentBuilder()
    .setTitle('测试接口文档')
    .setDescription('用来测试')
    .setVersion('1')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('/api-docs', app, document);

  app.useStaticAssets(path.join(__dirname, 'resource'), {
    prefix: '/xiaoluo'
  })
  // 设置超时时间（ms）
  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalInterceptors(new ResponseInterceptor());
  app.useGlobalFilters(new AllExceptionsFilter());

  const server = await app.listen(process.env.PORT ?? 3000);
  (server as any).setTimeout(10 * 60 * 1000);
}
bootstrap();
